<template>
	<view class="list-view">
		<view class="top-bar"><uni-navbar :show="show" @click-show="show = !show" :fixed="true" :back="true" color="#fff" :title="title"></uni-navbar></view>

		<view class="filter-box" v-if="show">
			<view class="form-box">
				<u-form ref="uForm">
					<u-form-item class="form-item" label="标题" labelAlign="left" label-width="190"><u-input v-model="perform.title" type="text" placeholder="请输入标题" /></u-form-item>
					<u-form-item class="form-item" label="届次" labelAlign="left" label-width="190">
						<u-input v-model="jieci" type="select" :select-open="jcShow" placeholder="请选择届次" @click="jcShow = true" />
						<u-select v-model="jcShow" mode="mutil-column-auto" :list="jcList" @confirm="jcConfirm"></u-select>
					</u-form-item>
				</u-form>
			</view>
			<view class="fiexd-btm">
				<view class="flex-box">
					<u-button class="form-btn" type="default" @click="resert">清除</u-button>
					<u-button class="form-btn" type="error" @click="filter">确定</u-button>
				</view>
			</view>
		</view>
		
		<view class="search-view">
			<u-search class="search-input" v-model="listQuery.title" :show-action="false" @search="search" @custom="show = !show"></u-search>
			<!-- <view class="" style="display: flex;align-items: center;">
				<image style="width: 26upx;height: 30upx;" src="../../../static/sx.png" mode=""></image>
				<text style="font-size: 14px;color: #666666;padding-left: 10upx;">筛选</text>
			</view> -->
		</view>
		
		
		<u-tabs scrollable class="uTabs" :list="tabsList" :is-scroll="false" v-model="tabsCurrent" @change="tabsChange"></u-tabs>

		<view class="list-box" >
			<view class="list-info_01" v-for="(item, index) of ysList" :key="index">
				<view class="info-title" @tap="indetail(item,'')">{{ item.title }}</view>
				<view class="info-btm" @tap="indetail(item,'')">
					<view class="btm-left clamp">
						<!-- <text class="left-name" >{{ item.createByName }}</text> -->
						<text class="left-time">{{ item.submitTime }}</text>
						<text class="left-time" style="padding-left: 20rpx;">{{ item.submitName }}</text>
					</view>
					<view class="btm-right">
						<!-- <view class="right-type" :style="'color:' + colorMap[item.nodeStatus]">{{ statusMap[item.nodeStatus] }}</view> -->
					</view>
				</view>
				
				<view class="changeBtnList">
					<view class="changeBtnListItem inch" v-if="tabsCurrent == 0" @tap="indetail(item,'scdycg')">
						上传调研成果
					</view>
					
					<view class="changeBtnListItem inwc minBtn" v-if="tabsCurrent == 0 && (!isDB || (isDB && !item.isCyrFlag)) "  @tap="indetail(item,'wc')">
						完成
					</view>
					
					<view class="changeBtnListItem inch" v-if="tabsCurrent == 1 && (!isDB || (isDB && !item.isCyrFlag))" @tap="indetail(item,'ksmsxs')">
						开始码上议事
					</view>
					
					<view class="changeBtnListItem inch" v-if="tabsCurrent == 2  && (isGLY || isZCRD || !isDB || isYtDb(item))" @tap="indetail(item,'scxscg')">
						上传议事成果
					</view>
					
					<view class="changeBtnListItem inwc minBtn" v-if="tabsCurrent == 2 && (isGLY || isZCRD || !isDB || isYtDb(item)) "  @tap="indetail(item,'yscgwc')">
						完成
					</view>
					
					<!-- <view class="changeBtnListItem inch" v-if="tabsCurrent == 2 && ( isGLY || isZCRD ) && !isDB" @tap="indetail(item,'zjbl')">
						自己办理
					</view>
					
					<view class="changeBtnListItem inch" v-if="tabsCurrent == 2 && ( isGLY || isZCRD ) && !isDB" @tap="indetail(item,'zsrd')">
						转市人大
					</view> -->
					
					<view class="changeBtnListItem bwc" v-if="tabsCurrent == 3 && (!isDB || (isDB && !item.isCyrFlag))" @tap="indetail(item,'tjrddbzj')">
						提交代表之家
					</view>
					
					<view class="changeBtnListItem inch" v-if="tabsCurrent == 3 && (!isDB || (isDB && !item.isCyrFlag))" @tap="indetail(item,'jsrdcwh')">
						提交人大常委会
					</view>
					
					<view class="changeBtnListItem inkssqdy" v-if="tabsCurrent == 3 && (!isDB || (isDB && !item.isCyrFlag))" @tap="indetail(item,'zwdbyajy')">
						转为议案建议
					</view>
					
					<view class="changeBtnListItem inch minBtn" v-if="tabsCurrent == 4 && (isGLY || isZCRD || isDBZJ ) && !isDB" @tap="indetail(item,'bl')">
						办理
					</view> 
					
					<view class="changeBtnListItem inch minBtn" v-if="tabsCurrent == 5" @tap="indetail(item,'ck')">
						查看
					</view>
					
					<view class="changeBtnListItem inch" v-if="tabsCurrent == 6" @tap="indetail(item,'ksjggs')">
						开始结果公示
					</view>
				</view>
				
				
			</view>
			
		</view>
		
		<view class="noMessage" v-if="isNoMessage">
			<view class="noMessageImg">
				<image src="@/static/result-img/no-data.png" mode=""></image>
			</view>
			<!-- <view class="noMessageText">
				暂无内容
			</view> -->
		</view> 
		
		<u-loadmore v-if="isno" :status="loading" />
		<image src="/static/img/icon_tianbao.png" mode="widthFix" class="tianbao" @click="editTo" v-if="$sysBtns(flag + '_add')"></image>
		<u-back-top :scroll-top="scrollTop" top="150" style="right: 40rpx; bottom: 50rpx"></u-back-top>

		<view v-if="false && flag"></view>
		
	</view>
</template>

<script> 
import { mapState } from 'vuex';
export default {
	data() {
		return {
			isNoMessage:false,
			isno:false,
			isDBZJ:false,
			isGLY:false,
			isZCRD:false,
			isDB:false,
			ysList:[],
			listQuery:{
				title:'',
				currentUserId:'',
				clientCode:'370782',
				dbzjDeptId:'',
				dataRange:'',
				isSource:'',
				isNode:'',
				isReview:'',
				flagNew:'',
				pageSize:'10',
				pageNum:'1'
			},
			scrollTop: 0,
			show: false,
			tabsCurrent: 0,
			tabsList: [
				{
					name:'议前调研'
				},
				{
					name:'待码上议事'
				},
				{
					name:'码上议事'
				},
				{
					name:'形成方案'
				},
				{
					name:'方案办理'
				},
				{
					name:'转议案建议'
				},
				
				{
					name:'待结果公示'
				}
			],
			colorMap: {
				0: '#303133',
				1: '#19be6b',
				2: '#ff9900',
				3: '#0099ff',
				4: '#ff3333'
			},
			statusMap: {
				0: '草稿',
				1: '待初审',
				2: '待审核',
				3: '通过',
				4: '不通过'
			},
			nodeStatus: -1,
			title: '人大会议',
			jieci: '',
			jcShow: false,
			jcList: [],
			flag: 'huiyi',
			dutiesList: [],

			perform: {
				ciId: '',
				jieId: '',
				status: '1',
				wyhdz: '',
				nodeStatus: '',
				module: '1',
				title: ''
			},
			loading: 'nomore'
		};
	},
	onShow(option) {
		this.loadLogin()
		
		if(this.$roleCodes('weiyuan')){
			this.isDB = true
		}else{
			this.isDB = false
		}
		
		if(this.$roleCodes('daibiaozhijia')){
			this.isDBZJ = true
		}else{
			this.isDBZJ = false
		}
		
		if(this.$roleCodes('sys_manager')){
			this.isGLY = true
		}else{
			this.isGLY = false
		}
		
		if(this.$roleCodes('zc_admin')){
			this.isZCRD = true
		}else{
			this.isZCRD = false
		}

		if(this.$roleCodes('daibiaozhijia')){
			this.isZCRD = true
		}else{
			this.isZCRD = false
		}
		this.getList(this.tabsCurrent)
	},
	onPullDownRefresh() {
		this.getList(this.tabsCurrent)
	},
	onReachBottom() {
		if(!this.isno && !this.isNoMessage){
			this.getAlllist(this.tabsCurrent)
		}
	},
	onPageScroll(res) {
		this.scrollTop = res.scrollTop;
	},
	computed: {
		...mapState(['userInfo']),
		listQueryTitle(){
			return this.listQuery.title
		}
	},
	watch:{
		listQueryTitle(e,v){
			this.getList(this.tabsCurrent)
		}
	},
	methods: {
		isYtDb(e){ 
			console.log("123",e.submitBy == uni.getStorageSync('userInfo').sysUser.id)
			if(e.submitBy == uni.getStorageSync('userInfo').sysUser.id){
				return true
			}else{
				return false
			}
		},
		indetail(e,v){
			let that = this
			if(v == 'wc'){
				let url = '/msIssueInfo/addSurveyEnd';
				let a = {
					issueId:e.id,
					currentUserId: this.userId,
				}
				
				
				this.$request(url, a , {
					load: true
				}).then((res) => {
					if(res.code == 200){
						that.$msg('已完成')
						that.getList(that.tabsCurrent)
					}
					
				});
				
			}
			else if(v== 'tjrddbzj'){
				let url = '/msIssueInfo/conTrfType';
				let a = {
					issueId:e.id,
					currentUserId: this.userId,
					isNode:'13',//提交人大代表之家：13；②提交市人大：11；③转议案建议：12
				}
				
				
				this.$request(url, a , {
					load: true
				}).then((res) => {
					if(res.code == 200){
						that.$msg('已提交')
						that.getList(that.tabsCurrent)
					}
				});
			}
			else if(v== 'jsrdcwh'){
				let url = '/msIssueInfo/conTrfType';
				let a = {
					issueId:e.id,
					currentUserId: this.userId,
					isNode:'11',//提交人大代表之家：13；②提交市人大：11；③转议案建议：12
				}
				
				
				this.$request(url, a , {
					load: true
				}).then((res) => {
					if(res.code == 200){
						that.$msg('已提交')
						that.getList(that.tabsCurrent)
					}
				});
			}
			else if(v== 'zwdbyajy'){
				let url = '/msIssueInfo/conTrfType';
				let a = {
					issueId:e.id,
					currentUserId: this.userId,
					isNode:'12',//提交人大代表之家：13；②提交市人大：11；③转议案建议：12
				}
				
				
				this.$request(url, a , {
					load: true
				}).then((res) => {
					if(res.code == 200){
						that.$msg('已转议案建议')
						that.getList(that.tabsCurrent)
					}
				});
			}
			else if(v == 'yscgwc'){
				let url = '/msIssueInfo/conNextScheme';
				let a = {
					issueId:e.id,
					currentUserId: this.userId,
				}
				this.$request(url, a , {
					load: false
				}).then((res) => {
					if(res.code == 200){
						that.$msg('已完成')
						that.getList(that.tabsCurrent)
					}
				});
			}
			else{
				uni.navigateTo({
					url:'../ytxsZDetail/ytxsZDetail?id=' + e.id + '&type=' + v + '&isCyrFlag=' + e.isCyrFlag + '&isDbzjFlag=' + e.isDbzjFlag + '&isFzrFlag=' + e.isFzrFlag
				})
			}
		},
		getList(e = 0){
			let that = this
			this.isno = false
			this.isNoMessage = false
			let url = '/msIssueInfo/list';
			let a = JSON.parse(JSON.stringify(that.listQuery))
			// 议前调研
			if(e == 0){
				a.isNode = '4'
				a.isReview = '1'
				a.flagNew = '4'
			}
			
			//带码上议事
			if(e == 1){
				a.isNode = '5'
				a.isReview = '0'
				a.flagNew = '5'
			}
			
			// 码上议事
			if(e == 2){
				a.isNode = '5'
				a.isReview = '1'
				a.flagNew = '5'
			}
			
			// 方案办理
			if(e == 3){
				a.isNode = '31'
				a.isReview = '0'
			}
			
			// 方案办理
			if(e == 4){
				a.isNode = '11,13'
				a.isReview = '0'
			}
			
			// 转议案建议
			if(e == 5){
				a.isNode = '12'
				a.isReview = '0'
			}
			
			// 待码上公开
			if(e == 6){
				a.isNode = '6'
				a.isReview = '0'
			}
			
			this.$request(url, a , {
				load: true
			}).then((res) => {
				if(res.code == 200){
					if(res.data && res.data.records.length !== 0){
						that.ysList = res.data.records
					}else{
						that.ysList = []
						that.isNoMessage = true
					}
				}
				
			});
		},
		getAlllist(e = 0){
			let that = this
			let url = '/msIssueInfo/list';
			let a = JSON.parse(JSON.stringify(that.listQuery))
			
			// 议前调研
			if(e == 0){
				a.isNode = '4'
				a.isReview = '1'
				a.flagNew = '4'
			}
			
			//带码上议事
			if(e == 1){
				a.isNode = '5'
				a.isReview = '0'
				a.flagNew = '5'
			}
			
			// 码上议事
			if(e == 2){
				a.isNode = '5'
				a.isReview = '1'
				a.flagNew = '5'
			}
			
			// 方案办理
			if(e == 3){
				a.isNode = '31'
				a.isReview = '0'
			}
			
			// 方案办理
			if(e == 4){
				a.isNode = '11,13'
				a.isReview = '0'
			}
			
			// 转议案建议
			if(e == 5){
				a.isNode = '12'
				a.isReview = '0'
			}
			
			// 待码上公开
			if(e == 6){
				a.isNode = '6'
				a.isReview = '0'
			}
			
			a.pageNum++
			
			this.$request(url, a , {
				load: true
			}).then((res) => {
				if(res.code == 200){
					if(res.data.records.length !== 0){
						that.listQuery.pageNum++
						that.ysList.push(...res.data.records)
					}else{
						that.isno = true
						
					}
				}
				
			});
		},
		loadLogin() {
			if (this.userInfo.sysUser) {
				this.clientCode = this.userInfo.sysUser.clientCode;
				this.userId = this.userInfo.sysUser.id;
				this.roleCodes = this.userInfo.roleCodes.join(',');

				this.pageNum = 1;
				this.pageSize = 10;
			} else {
				this.$logout();
			}
		},
		loadData(type = 'add') {
			if (this.loading == 'loading') {
				return false;
			}
			if (type == 'add') {
				if (this.loading == 'nomore') {
					return false;
				}
				this.loading = 'loading';
			} else {
				this.loading = 'loading';
			}
			if (type != 'add') {
				this.pageNum = 1;
			}
			if (this.perform.nodeStatus == '-1') {
				this.perform.nodeStatus = '';
			}
			let data = {
				pageNum: this.pageNum,
				pageSize: this.pageSize,
				currentUserId: this.userId,
				clientCode: this.clientCode,
				roleCodes: this.roleCodes,
				perform: this.perform
			};
			this.$request('/perform/myList', data, {
				load: true
			}).then((res) => {
				let count = 0;
				if (type != 'add') {
					uni.stopPullDownRefresh();
					this.dutiesList = [];
				}
				this.loading = this.pageNum < Math.ceil(res.data.total / this.pageSize) ? 'loadmore' : 'nomore';
				this.pageNum = this.pageNum + 1;
				this.dutiesList = this.dutiesList.concat(res.data.records);
				this.loaded = true;
				if (this.dutiesList.length <= 0) {
					this.loading = 'nodata';
				}
			});
		},
		loadDict(type) {
			this.$request('/system/sys-dict/dictList', {
				clientCode: this.clientCode,
				sysDict: {
					dictType: type
				}
			}).then((res) => {
				this.tabsList.push({
					name: '所有',
					value: '-1'
				});
				res.data.forEach((item) => {
					this.tabsList.push({
						name: item.dictName,
						value: item.dictValue
					});
				});
			});
		},
		tabsChange(index) {
			this.isNoMessage = false
			this.isno = false
			this.tabsCurrent = index;
			this.getList(index)
		},
		jcConfirm(e) {
			this.jieci = e[0].label + e[1].label;
			this.perform.jieId = e[0].value;
			this.perform.ciId = e[1].value;
		},
		filter() {
			this.show = false;
			this.loadData('refresh');
		},
		resert() {
			this.show = false;
			this.perform.title = '';
			this.jieci = '';
			this.perform.jieId = '';
			this.perform.ciId = '';
			this.loadData('refresh');
		},
		search(e) {
			this.perform.title = e;
			this.loadData('refresh');
		},
		type(e) {
			this.nodeStatus = e;
			this.perform.nodeStatus = e.toString();
			this.loadData('refresh');
		},
		jieciData() {
			let data = {
				clientCode: this.clientCode,
				jieCi: {
					pid: ''
				}
			};
			this.$request('/jie-ci/list', data).then((res) => {
				this.jcList = [];
				let jieArr = [];
				let ciArr = [];
				res.data.forEach((item) => {
					data.jieCi.pid = item.id;
					this.$request('/jie-ci/list', data).then((res) => {
						ciArr = [];
						res.data.forEach((key) => {
							ciArr.push({
								value: key.id,
								label: key.name
							});
						});
						this.jcList.push({
							value: item.id,
							label: item.name,
							children: ciArr
						});
					});
				});
			});
		},
		navTo(item) {
			uni.navigateTo({
				url: '/pagesA/duties/detail?flag=' + this.flag + '&code=' + this.perform.module + '&name=' + this.title + '&id=' + item.id
			});
		},
		editTo(item) {
			uni.navigateTo({
				url: '/pagesA/duties/add?flag=' + this.flag + '&code=' + this.perform.module + '&name=' + this.title
			});
		}
	}
};
</script>

<style lang="scss" scoped>
.uTabs {
	min-height: 88rpx;
}

.list-box {
	padding: 0 30rpx;
	background-color: #fff;
}

.tianbao {
	display: block;
	position: fixed;
	right: 40rpx;
	bottom: 170rpx;
	width: 160rpx;
	height: 160rpx;
}

.filter-box {
	position: fixed;
	left: 0;
	top: 0;
	bottom: 0;
	right: 0;
	z-index: 998;
	background-color: #fff;
}

.form-box {
	.form-item {
		@include mp-flex;
		border-bottom: 20rpx solid #f5f7fa;
	}
}

.fiexd-btm {
	position: static;
	padding: 30rpx;
}

.bottomBtn{
	position: fixed;
	bottom: 200upx;
	right: 20upx;
	width: 100upx;
	height: 100upx;
	text-align: center;
	background-color: red;
	border-radius: 50%;
	padding: 10upx;
	color: #fff;
	.bottomBtnInfo{
		font-size: 15px;
	}
}

.changeBtnList{
	display: flex;
	align-items: center;
	justify-content: flex-end;
	flex-wrap: wrap;
	margin-top: 20upx;
	.changeBtnListItem{
		padding: 10upx ;
		border: 1upx solid #999999;
		margin: 0 10upx;
		font-size: 14px; 
	}
}


.inkssqdy{
	color: #D26371 !important;
	border: 1upx solid #D26371 !important;
	border-radius: 50upx;
}

.inch{
	color: #F5A623 !important;
	border: 1upx solid #F5A623 !important;
	border-radius: 50upx;
}

.inwc{
	color: #999999 !important;
	border: 1upx solid #999999 !important;
	border-radius: 50upx;
}

.bwc{
	color: #3396FB !important;
	border: 1upx solid #3396FB !important;
	border-radius: 50upx;
}

.u-tab-item.data-v-48634e29 {
	padding: 0 20upx !important;
}

.noMessage{
	background-color: #f6f7fb;
	display: flex;
	justify-content: center;
	justify-items: center;
	flex-direction:column;
	margin-top: 80upx;
	.noMessageImg{
		text-align: -webkit-center;
		image{
			width: 676rpx;
			    height: 352rpx;
		}
	}
	
	.noMessageText{
		margin-top: 30upx;
		font-size: 40upx;
		color: #666666;
		text-align: center;
	}
}

.u-load-more-wrap{
	background: none !important;
}

.u-more-text{
	background: none !important;
}

.minBtn{
	min-width: 125upx;
	text-align: center;
}
</style>
